package com.jjlin.chapter_8;

import java.util.*;
public class CD8{

    //求未排序正数数组中累加和为给定值的最大子数组长度
    //时间复杂度为O(N),空间复杂度为O(1)
    public static int getMaxLength(int[] arr, int k){
        if(arr == null || arr.length == 0 || k <= 0)
            return 0;
        int left = 0;//维护一个arr[left..right]的动态窗口
        int right = 0;
        int sum = arr[left];//记录窗口中的所有数的总和
        int len = 0;//窗口的长度
        while(left <= right && right < arr.length){
            if(sum == k){
                len = Math.max(right - left + 1, len);
                sum -= arr[left++];
            }else if(sum < k){
                right++;
                if(right == arr.length)
                    break;
                sum += arr[right];
            }else{
                sum -= arr[left++];
            }
        }
        return len;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
            arr[i] = sc.nextInt();
        System.out.println(getMaxLength(arr, k));
    }
}